<template>
	<sw-common-frame :count="dataCount" :loading="loading">
		<template slot="button">
			<el-button size="small" type="primary" icon="el-icon-plus" @click="handleOpenDialog()">新增</el-button>
		</template>
		<template slot="query">
			<el-form size="small" inline>
				<el-form-item>
					<el-input v-model="queryData.name" clearable placeholder="请输入试卷名称" style="width: 180px"></el-input>
				</el-form-item>
				<el-form-item>
					<el-select v-model="queryData.paperType" clearable placeholder="试卷类型" style="width: 102px">
						<el-option label="普通试卷" value="1"></el-option>
						<el-option label="随机试卷" value="2"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-select v-model="queryData.permission" clearable placeholder="管理权限" style="width: 102px">
						<el-option label="完全私有" value="1"></el-option>
						<el-option label="只读共享" value="2"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-select v-model="queryData.status" clearable placeholder="试卷状态" style="width: 102px">
						<el-option label="正常" value="1"></el-option>
						<el-option label="禁用" value="2"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData()">查询</el-button>
				</el-form-item>
			</el-form>
		</template>
		<el-table slot="table" :data="tableData" height="100%" stripe>
			<el-table-column label="排序" type="index" width="50" align="center"></el-table-column>
			<el-table-column label="试卷名称" prop="name" width="230">
				<el-link :underline="false" slot-scope="{ row }">{{ row.name }}</el-link>
			</el-table-column>
			<el-table-column label="试卷分类" prop="sysClassify.name" min-width="90"></el-table-column>
			<el-table-column label="试卷类型" min-width="90">
				<template slot-scope="{ row }">
					<font color="#409EFF" v-if="row.permission === '1'">普通试卷</font>
					<font color="#67C23A" v-if="row.permission === '2'">随机试卷</font>
				</template>
			</el-table-column>
			<el-table-column label="试卷状态" min-width="90">
				<template slot-scope="{ row }">
					<el-tag size="medium" type="success" v-if="row.status === '1'">正常</el-tag>
					<el-tag size="medium" type="warning" v-if="row.status === '2'">禁用</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="总分" prop="totalScore" min-width="90"></el-table-column>
			<el-table-column label="管理权限" min-width="90">
				<template slot-scope="{ row }">
					<el-tag size="medium" type="success" v-if="row.permission === '1'">完全私有</el-tag>
					<el-tag size="medium" type="warning" v-if="row.permission === '2'">只读共享</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="创建时间" prop="createTime" min-width="160"></el-table-column>
			<el-table-column label="操作" width="210">
				<el-button-group slot-scope="{ row }">
					<el-button size="mini" type="info" @click="handleConfigChapter(row.id)">章节配置</el-button>
					<el-button size="mini" type="warning" @click="handleOpenDialog(row.id)">编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDeleteData(row)">删除</el-button>
				</el-button-group>
			</el-table-column>
		</el-table>
		<template slot="page">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
		</template>
		<form-dialog v-model="formDialog" :data-id="dataId" @refresh="queryTableData()"></form-dialog>
	</sw-common-frame>
</template>

<script>
import formDialog from './form';
import chapterConfig from './chapter';
import listMixins from '@/mixins/listMixins';
import { queryPapersList, deletePapers } from '@/api/exam/testPaper';
const baseUrl = !window.baseUrl ? process.env.VUE_APP_BASEURL : window.baseUrl;
export default {
	mixins: [listMixins],
	components: { formDialog, chapterConfig },
	data() {
		return {
			pageName: '试卷',
			pagersId: '',
			configDialog: false
		};
	},
	computed: {
		listFunction() {
			return eval(queryPapersList);
		},
		deleteFunction() {
			return eval(deletePapers);
		}
	},
	mounted() {},
	methods: {
		handleConfigChapter(id) {
			this.pagersId = id;
			this.configDialog = true;
		}
	}
};
</script>

<style lang="scss" scoped></style>
